
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.FreightTemplatCharge;
import com.shop.cloud.mall.admin.service.FreightTemplatChargeService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 运费模板规则
 *
 * @author
 * @date 2023-10-10 11:06:56
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/freighttemplatcharge")
@Tag(description = "freighttemplatcharge", name = "运费模板规则管理")
public class FreightTemplatChargeController {

    private final FreightTemplatChargeService freightTemplatChargeService;

    /**
     * 运费模板规则分页列表
     * @param page 分页对象
     * @param freightTemplatCharge 运费模板规则
     * @return
     */
    @Operation(summary = "运费模板规则分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:freighttemplatcharge:index')")
    public R getPage(Page page, FreightTemplatCharge freightTemplatCharge) {
        return R.ok(freightTemplatChargeService.page(page, Wrappers.query(freightTemplatCharge)));
    }

    /**
     * 运费模板规则查询
     * @param id
     * @return R
     */
    @Operation(summary = "运费模板规则查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:freighttemplatcharge:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(freightTemplatChargeService.getById(id));
    }

    /**
     * 运费模板规则新增
     * @param freightTemplatCharge 运费模板规则
     * @return R
     */
    @Operation(summary = "运费模板规则新增")
    @SysLog("新增运费模板规则")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:freighttemplatcharge:add')")
    public R save(@RequestBody FreightTemplatCharge freightTemplatCharge) {
        return R.ok(freightTemplatChargeService.save(freightTemplatCharge));
    }

    /**
     * 运费模板规则修改
     * @param freightTemplatCharge 运费模板规则
     * @return R
     */
    @Operation(summary = "运费模板规则修改")
    @SysLog("修改运费模板规则")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:freighttemplatcharge:edit')")
    public R updateById(@RequestBody FreightTemplatCharge freightTemplatCharge) {
        return R.ok(freightTemplatChargeService.updateById(freightTemplatCharge));
    }

    /**
     * 运费模板规则删除
     * @param id
     * @return R
     */
    @Operation(summary = "运费模板规则删除")
    @SysLog("删除运费模板规则")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:freighttemplatcharge:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(freightTemplatChargeService.removeById(id));
    }

    /**
     * 通过模板ID查运费模板规则list
     * @param freightTemplatId
     * @return R
     */
    @Operation(summary = "通过模板ID查运费模板规则list")
    @GetMapping("/list/{freightTemplatId}")
    public R listByFreightTemplatId(@PathVariable("freightTemplatId") String freightTemplatId) {
        return R.ok(freightTemplatChargeService.list(Wrappers.<FreightTemplatCharge>query().lambda()
                .eq(FreightTemplatCharge::getFreightTemplatId, freightTemplatId))
        );
    }
}
